create or replace package body m_tx is

procedure tx_links is
begin
  htp.tableOpen;
    htp.tableRowOpen;
      htp.tableData(htf.anchor('m_tx.tx_insert','Insert Employee'));
      htp.tableData(htf.anchor('m_tx.tx_delete','Delete Employee'));
      htp.tableData(htf.anchor('show_open_sessions','Open Sessions',cattributes=>'target="_sessions"'));
    htp.tableRowClose;
    htp.tableRowOpen;
      htp.tableData(htf.anchor('m_tx.tx_start','Start Transaction'));
      htp.tableData(htf.anchor('m_tx.tx_end','Commit Transaction'));
      htp.tableData(htf.anchor('m_tx.tx_rollback','Rollback Transaction'));
      htp.tableData(htf.anchor('m_tx.tx_show','Show Employees'));
    htp.tableRowClose;
  htp.tableClose;
end tx_links;

procedure tx_start is
begin
	htp.htmlOpen;
	htp.headOpen;
	htp.title('Transaction Started...');
	htp.headClose;
	htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	htp.center(htf.header(3,owa_util.get_cgi_env('SERVER_SOFTWARE')||' Transaction Started...'));
	tx_links;
  m_tx.tx_disp;
  demo.link;
  htp.bodyClose;
  htp.htmlClose;
end tx_start;
/*----------------------------------------------------------------------------------------
*/

procedure tx_end is
begin
	htp.htmlOpen;
	htp.headOpen;
	htp.title('Transaction Commited...');
	htp.headClose;
	htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	htp.center(htf.header(3,owa_util.get_cgi_env('SERVER_SOFTWARE')||' Transaction Commited...'));
	tx_links;
  demo.link;
  htp.bodyClose;
  htp.htmlClose;
end tx_end;
/*----------------------------------------------------------------------------------------
*/

procedure tx_rollback is
begin
	htp.htmlOpen;
	htp.headOpen;
	htp.title('Transaction Rolled back...');
	htp.headClose;
	htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	htp.center(htf.header(3,owa_util.get_cgi_env('SERVER_SOFTWARE')||' Transaction Rolled back...'));
	tx_links;
  demo.link;
  htp.bodyClose;
  htp.htmlClose;
end tx_rollback;
/*----------------------------------------------------------------------------------------
*/

procedure tx_insert is
v_emp_id number;
begin
  select s_emp_id.nextval into v_emp_id from dual;
  insert into s_emp (id,last_name,first_name,salary) values (v_emp_id,'Ochoa','Marcelo',20000+v_emp_id);
	htp.htmlOpen;
	htp.headOpen;
	htp.title('Employee Inserted...');
	htp.headClose;
	htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	htp.center(htf.header(3,owa_util.get_cgi_env('SERVER_SOFTWARE')||' Employee Inserted...'));
	tx_links;
  m_tx.tx_disp;
  demo.link;
  htp.bodyClose;
  htp.htmlClose;
exception
when others then
	 htp.htmlOpen;
	 htp.headOpen;
	 htp.title('Exception...');
	 htp.headClose;
	 htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	 htp.center(htf.header(3,SQLERRM));
	 tx_links;
   htp.bodyClose;
   htp.htmlClose;
end tx_insert;
/*----------------------------------------------------------------------------------------
*/

procedure tx_delete is
begin
  delete from s_emp where last_name='Ochoa';
	htp.htmlOpen;
	htp.headOpen;
	htp.title('Employee Deleted...');
	htp.headClose;
	htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	htp.center(htf.header(3,owa_util.get_cgi_env('SERVER_SOFTWARE')||' Employee Deleted...'));
	tx_links;
  m_tx.tx_disp;
  demo.link;
  htp.bodyClose;
  htp.htmlClose;
exception
when others then
	 htp.htmlOpen;
	 htp.headOpen;
	 htp.title('Exception...');
	 htp.headClose;
	 htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	 htp.center(htf.header(3,SQLERRM));
	 tx_links;
   demo.link;
   htp.bodyClose;
   htp.htmlClose;
end tx_delete;
/*----------------------------------------------------------------------------------------
*/

procedure tx_show is
begin
	htp.htmlOpen;
	htp.headOpen;
	htp.title('Show Employees');
	htp.headClose;
	htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	htp.center(htf.header(3,owa_util.get_cgi_env('SERVER_SOFTWARE')||' Show Employees'));
	tx_links;
  m_tx.tx_disp;
  demo.link;
  htp.bodyClose;
  htp.htmlClose;
exception
when others then
	 htp.htmlOpen;
	 htp.headOpen;
	 htp.title('Exception...');
	 htp.headClose;
	 htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	 htp.center(htf.header(3,SQLERRM));
	 tx_links;
   demo.link;
   htp.bodyClose;
   htp.htmlClose;
end tx_show;
/*----------------------------------------------------------------------------------------
*/

procedure tx_disp is
dummy boolean;
begin
  dummy:=owa_util.tablePrint(ctable=>'s_emp',ccolumns=>'id,last_name,salary');
  tx_links;
exception
when others then
	 htp.htmlOpen;
	 htp.headOpen;
	 htp.title('Exception...');
	 htp.headClose;
	 htp.bodyOpen(cattributes=>'aLink=#008040 bgColor=#ffffff link=#0000ff text=#000000 vLink=#ff0000');
	 htp.center(htf.header(3,SQLERRM));
	 tx_links;
   demo.link;
   htp.bodyClose;
   htp.htmlClose;
end tx_disp;
/*----------------------------------------------------------------------------------------
*/
begin
   -- where can I find xml stylesheets
   url_server := owa_util.get_cgi_env('REQUEST_PROTOCOL')||'://'||
                 owa_util.get_cgi_env('SERVER_NAME')||':'||
                 owa_util.get_cgi_env('SERVER_PORT');
end;
/
